package com.pojocreator.Utils;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.pojocreator.common.CommonConstants;
import com.pojocreator.common.CommonConstants.Datatype;

public class CommonUtils {
	private static final Log log = LogFactory.getLog(CommonUtils.class);
	
	public static Class<?> getEquivalentJavaTypeAsClass(Datatype type){
		Class<?> javaType=null;
		
		switch(type){
			case VARCHAR:{
				javaType=CommonConstants.ORACLE_DATATYPE_VARCHAR_CLASS;
				break;
			}
			case INT: {
				javaType=CommonConstants.ORACLE_DATATYPE_INT_CLASS;
				break;
			}
			case DATE:{
				javaType=CommonConstants.ORACLE_DATATYPE_DATE_CLASS;
				break;
			}
			case BLOB: {
				javaType=CommonConstants.ORACLE_DATATYPE_BLOB_CLASS;
				break;
			}
			case TIMESTMP:{
				javaType=CommonConstants.ORACLE_DATATYPE_TIME_STAMP_CLASS;
				break;
			}
			case CLOB: {
				javaType=CommonConstants.ORACLE_DATATYPE_CLOB_CLASS;
				break;
			}
			default:{
				//Treat as String
				javaType=CommonConstants.ORACLE_DATATYPE_VARCHAR_CLASS;
				break;
			}
		}
		log.debug(javaType.toString());
		return javaType;
	}
	public static Datatype getEquivalentEnum(String dataType){
		
		if(dataType.contains(CommonConstants.ORACLE_DATATYPE_VARCHAR_VALUE)){
			return Datatype.VARCHAR;
		}else if(dataType.contains(CommonConstants.ORACLE_DATATYPE_BLOB_VALUE)){
			return Datatype.BLOB;
		}else if(dataType.contains(CommonConstants.ORACLE_DATATYPE_CLOB_VALUE)){
			return Datatype.CLOB;
		}else if(dataType.contains(CommonConstants.ORACLE_DATATYPE_DATE_VALUE)){
			return Datatype.DATE;
		}else if(dataType.contains(CommonConstants.ORACLE_DATATYPE_INT_VALUE)){
			return Datatype.INT;
		}else if(dataType.contains(CommonConstants.ORACLE_DATATYPE_TIMESTMP_VALUE)){
			return Datatype.TIMESTMP;
		}
		return Datatype.VARCHAR;
	}
	public static String getCamelCasedName(String input){
		StringBuilder result=new StringBuilder();
		if(!StringUtils.isBlank(input)){
			char a=input.toUpperCase().charAt(0);
			result=result.append(a);
			result=result.append(input.substring(1).toLowerCase());
		}else {
			return null;
		}
		return result.toString();
	}
	public static void main(String s[]){
		System.out.println(getCamelCasedName("as_asdf"));
		System.out.println(getCamelCasedName("asaasaAaSASf"));
	}
}
